﻿#include "FramePropertyEditEntry.h"
#include "EnumEditEntry.h"
#include "IntegerEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(Frame)

struct FramePropertyEditEntry::FrameEditEntryPrivate {
	QPointer<QFrame> frame;
	QPointer<EnumEditEntry> entryFrameShape;
	QPointer<EnumEditEntry> entryFrameShadow;
	QPointer<IntegerEditEntry> entryLineWidth;
	QPointer<IntegerEditEntry> entryMidLineWidth;
};

FramePropertyEditEntry::~FramePropertyEditEntry() { }

FramePropertyEditEntry::FramePropertyEditEntry(QWidget *parent) : PropertyEditEntry {parent} {
	p.reset(new FrameEditEntryPrivate);
	initUi();
    retranslateUi();
}

FramePropertyEditEntry::FramePropertyEditEntry(void *object, QWidget *parent) : PropertyEditEntry {parent} {
    p.reset(new FrameEditEntryPrivate);
    initUi();
    retranslateUi();
    setObject(object);
}

void FramePropertyEditEntry::setObject(void* object) {
	QFrame* frame = static_cast<QFrame*>(object);
	Q_ASSERT(Q_LIKELY(frame));
	p->frame = frame;
}

void FramePropertyEditEntry::onTick() {
	if (!p->frame || !isVisible()) {
		return;
	}

	p->entryFrameShape->setValue(p->frame->frameShape());
	p->entryFrameShadow->setValue(p->frame->frameShadow());
	p->entryLineWidth->setValue(p->frame->lineWidth());
	p->entryMidLineWidth->setValue(p->frame->midLineWidth());
}

void FramePropertyEditEntry::initUi() {
	p->entryFrameShape = new EnumEditEntry;
	p->entryFrameShape->setMetaEnum(QMetaEnum::fromType<QFrame::Shape>());
	appendChildEntry(p->entryFrameShape);

	p->entryFrameShadow = new EnumEditEntry;
	p->entryFrameShadow->setMetaEnum(QMetaEnum::fromType<QFrame::Shadow>());
	appendChildEntry(p->entryFrameShadow);

	p->entryLineWidth = new IntegerEditEntry;
	appendChildEntry(p->entryLineWidth);

	p->entryMidLineWidth = new IntegerEditEntry;
	appendChildEntry(p->entryMidLineWidth);
}

void FramePropertyEditEntry::retranslateUi() {
    setTitle("QFrame");
	p->entryFrameShape->setTitle(tr("frameShape"));
	p->entryFrameShadow->setTitle(tr("frameShadow"));
	p->entryLineWidth->setTitle(tr("lineWidth"));
	p->entryMidLineWidth->setTitle(tr("midLineWidth"));
}
